package com.yanqu.road.server.manager.activity.celebration;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.celebration.CelebrationActivityConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.logic.bussiness.activity.CelebrationBusiness;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.server.CrossBaseServer;
import com.yanqu.road.server.manager.activity.ActivityInfoMgr;
import com.yanqu.road.server.manager.activity.seacraftsouthsea.SeacraftSouthSeaConfigMgr;
import com.yanqu.road.utils.date.DateHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description
 * @Author cwq
 * @Data 2022/4/24 16:31
 */
public class CelebrationConfigMgr {

    private static Logger logger = LogManager.getLogger(SeacraftSouthSeaConfigMgr.class.getName());

    private static Map<Integer, CelebrationActivityConfig> configMap = new ConcurrentHashMap<>();


    public static synchronized void reloadConfig() {
        logger.info("start reload Celebration activity config  start");
        String nowTimeStr = DateHelper.getCurrentDateTimeString();
        List<Integer> activityTypeList = new ArrayList<>();
        activityTypeList.add(eActivityType.CelebrationActivity.getValue());

        Map<Integer, ActivityInfo> activityInfoMap = ActivityBussiness.getOpenCrossRankActivityInfoMapByCrossServerId(activityTypeList, nowTimeStr, CrossBaseServer.getInstance().getServerId());
        for (ActivityInfo item : activityInfoMap.values()) {
            reloadConfig(item);
        }
        logger.info("start reload Celebration activity config  end");
    }


    public static synchronized void reloadConfig(ActivityInfo activityInfo) {
        CelebrationActivityConfig tempCelebrationActivityConfig = new CelebrationActivityConfig();
        tempCelebrationActivityConfig.setScoreConfigList(CelebrationBusiness.getCelebrationScoreConfigList(activityInfo.getActivityId()));
        tempCelebrationActivityConfig.parseConfig(activityInfo);

        configMap.put(activityInfo.getActivityId(), tempCelebrationActivityConfig);
    }


    public static Map<Integer, CelebrationActivityConfig> getConfigMap() {
        return configMap;
    }


}
